<!DOCTYPE html>
<html lang="en" xmlns:th="http://www.thymeleaf.org">
<head>
    <meta charset="UTF-8">
    <title>百度权重知乎excel下载</title>
    <!--<script type="text/javascript" src="/static/jquery-3.3.1.min.js"></script>-->
    <script type="text/javascript">
        var websocket = null;
        var myDate = new Date();
        //获取当前时间(从1970.1.1开始的毫秒数,时间戳)
        var time = myDate.getTime();
        //判断当前浏览器是否支持WebSockets
        if ('WebSocket' in window) {
            //ws统一标识符基于http请求，wss标识符基于https请求
            // websocket = new WebSocket("wss://famcoin.vip/CHAIN/websocket/c2ctradsocket/123456");
            // websocket = new WebSocket("ws://localhost:8081/CHAIN/websocket/c2ctradsocket/26");
            // websocket = new WebSocket("ws://localhost:8001/pc/websocket/"+time);//http
            websocket = new WebSocket("wss://xaxaxax.xyz/websocket/"+time);//https

        } else {
            alert("浏览器不支持");
        }

        //连接发生错误回调方法
        websocket.onerror = function (event) {
            setMessageInnerHTML("WebSocket连接发生错误");
        };

        //连接成功建立的回调方法
        websocket.onopen = function (event) {
            setMessageInnerHTML("连接成功");
        };

        //接收到消息的回调方法
        websocket.onmessage = function (event) {
            setMessageInnerHTML(event.data);
        };

        //连接关闭的回调方法
        websocket.onclose = function () {
            setMessageInnerHTML("连接关闭");
        };

        //监听窗口关闭事件，当窗口关闭时，主动去关闭websocket连接，防止连接还没断开就关闭窗口，server端会抛异常。
        window.onbeforeunload = function () {
            closeWebSocket();
        };

        //将消息显示在网页上
        function setMessageInnerHTML(innerHTML) {
            document.getElementById('message').innerHTML += innerHTML + '<br/>';
        }

        //关闭WebSocket连接
        function closeWebSocket() {
            websocket.close();
        }

        //发送消息
        function send() {
            var message = document.getElementById('text').value;
            websocket.send(message);
        }

        function req() {
            // var url = 'http://localhost:8001/pc/BaiDuZhiShu/'+time;//本地http
            var url = 'https://xaxaxax.xyz/pc/BaiDuZhiShu/'+time;//线上https
            //页面跳转
            // window.location.href ='http://localhost:8001/pc/BaiDuZhiShu/'+time;
            //ajax请求数据接口
            // $.ajax({url:'http://localhost:8001/pc/BaiDuZhiShu/'+time,async:false});
            // window.open(url, "_blank", "scrollbars=yes,resizable=1,modal=false,alwaysRaised=yes");
            //不打开新窗口，打开本页面的隐藏iframe（页面不展示）
            window.open(url, "aa");
            //XMLHttpRequest同步/异步的方式
            /*var xhr = new XMLHttpRequest();
            xhr.open('GET', url, true);//get请求，请求地址，是否异步
            xhr.responseType = "blob";    // 返回类型blob
            xhr.onload = function () {// 请求完成处理函数
                if (this.status === 200) {
                    var blob = this.response;// 获取返回值
                    var a = document.createElement('a');
                    a.download = 'time.xlsx';
                    a.href=window.URL.createObjectURL(blob);
                    a.click();
                }
            };
            // 发送ajax请求
            xhr.send();*/
        }
    </script>
</head>
<body>
<div>
    <button onclick="req()">百度权重知乎，下载excel</button>
    <iframe name="aa" hidden></iframe>
    <div id="message"></div>
</div>
</body>
</html>